#include "newstyle.hpp"
#include "ui_newstyle.h"

NewStyle::NewStyle(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::NewStyle)
{
    ui->setupUi(this);
    connect(this,SIGNAL(sendNewStyle(ChartStyle*)),parent,SLOT(getNewStyle(ChartStyle*)));

    //const QStringList colorNames = QColor::colorNames();
    QStringList colorNames;
    colorNames<<"red"<<"green"<<"blue"<<"magenta"<<"cyan"<<"yellow"<<"black";
    int index = 0;
    foreach ( const QString & colorName, colorNames ) {
        const QColor color(colorName);
        ui->comboBox->addItem(colorName, color);
        const QModelIndex idx = ui->comboBox->model()->index(index++, 0);
        ui->comboBox->model()->setData(idx, color, Qt::BackgroundColorRole);
    }
    this->newStyle = new ChartStyle();
}

NewStyle::~NewStyle()
{
    delete ui;
}

void NewStyle::on_comboBox_activated(int index) //kolor
{
    QString temp;
    temp.setNum(index+1);
    this->newStyle->_LineColor = temp.toAscii().data();
}

void NewStyle::on_comboBox_2_activated(int index) //lw
{
    QString temp;
    temp.setNum(index+1);
    this->newStyle->_LineWidth = temp.toAscii().data();
}

void NewStyle::on_comboBox_3_activated(int index) //pt
{
    QString temp;
    temp.setNum(index+1);
    this->newStyle->_PointType = temp.toAscii().data();
}

void NewStyle::on_comboBox_4_activated(int index) //ps
{
    QString temp;
    temp.setNum(index+1);
    this->newStyle->_PointSize = temp.toAscii().data();
}

void NewStyle::on_buttonBox_accepted()
{
    emit this->sendNewStyle(this->newStyle);
}

void NewStyle::on_pushButton_clicked()
{
    QDialog *wimage = new QDialog();
    wimage->setWindowTitle("Choose Point Type");
    wimage->setFixedSize(444,301);
    wimage->show();

    QLabel *image = new QLabel(wimage);
    image->setPixmap(QPixmap(QDir::homePath() + "/.XViz/rsc/pt.png"));
    image->show();
}
